听音乐
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using musicforme;
namespace musicforme
{
public partial class MainForm : Form
{
public MusicContorl MusicContorl = new MusicContorl();
public MainForm()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
}
protected override CreateParams CreateParams
{
//任务栏放大缩放窗体
get
{
CreateParams cp = base.CreateParams;
cp.Style = cp.Style | 0x20000;//允许最小化操作
return cp;
}
}
private void MainForm_Load(object sender, EventArgs e)
{
for (int i = 0; i < 13; i )
{
this.songListpanel.Controls.Add(MusicContorl.SongLabelList[i]);
this.MusicContorl.SongLabelList[i].Click = new EventHandler(SongLbl_Click);
this.MusicContorl.SongLabelList[i].DoubleClick = new EventHandler(SongLbl_DoubleClic);
}
this.MusicContorl.MusicPlayButton.Click = new System.EventHandler(MusicPlayButton_Click);
this.Controls.Add(MusicContorl.MusicPlayButton);
this.Controls.Add(this.MusicContorl.MusicBoxPlayer);
this.MusicTitlePanel.Controls.Add(this.MusicContorl.MusicNameTitle);
this.songListpanel.Controls.Add(this.MusicContorl.SongPagelbl);
this.Controls.Add(this.MusicContorl.MyMusicBar);
this.Controls.Add(MusicContorl.MyVolumBar);
this.MusicTitlePanel.Controls.Add(this.MusicContorl.MusicNameTitle);
var threadMusicBar = new Thread(MusicContorl.ThreadProgressBar) { IsBackground = true };
threadMusicBar.Start();
timer1.Start();
LoadMusicList();
MusicContorl.VolumeSet();
}
private void SongLbl_Click(object sender, EventArgs e)
{
this.MusicContorl.SongCursorCtrl(sender);
}
private void SongLbl_DoubleClic(object sender,EventArgs e)
{
this.MusicContorl.SongPlaySelect(sender);
}
private void MusicPlayButton_Click(object sender,EventArgs e)
{
MusicContorl.PlayPauseMusic();
}
private Point mousePoint;
private void MainForm_MouseDown(object sender, MouseEventArgs e)
{
//鼠标点击位置
//if (MouseButtons.Left != e.Button) return;
Point cur = this.PointToScreen(e.Location);
mousePoint = new Point(cur.X - this.Left, cur.Y - this.Top);
}
private void MainForm_MouseMove(object sender, MouseEventArgs e)
{
//窗体随鼠标移动
if (MouseButtons.Left != e.Button) return;
Point cur = MousePosition;
this.Location = new Point(cur.X - mousePoint.X, cur.Y - mousePoint.Y);
}
private void mFormClose_Click(object sender, EventArgs e)
{
//关闭运用
MusicContorl.pasueMusic();
Application.Exit();
}
private void mFormMin_Click(object sender, EventArgs e)
{
//最小化窗体
this.WindowState = FormWindowState.Minimized;
}
private void mFormClose_MouseEnter(object sender, EventArgs e)
{
//经过close
mFormClose.ForeColor = System.Drawing.Color.Yellow;
}
private void mFormClose_MouseLeave(object sender, EventArgs e)
{
//离开closebtn
mFormClose.ForeColor = System.Drawing.Color.White;
}
private void mFormMin_MouseEnter(object sender, EventArgs e)
{
//经过min
mFormMin.ForeColor = System.Drawing.Color.Yellow;
}
private void mFormMin_MouseLeave(object sender, EventArgs e)
{
//离开min
mFormMin.ForeColor = System.Drawing.Color.White;
}
int mod=0;
private void timer1_Tick(object sender, EventArgs e)
{
SongTimelbl.Text = MusicContorl.Timelable;
switch (mod)
{
case 1:
btnLastMusic.BackgroundImage = global::musicforme.Properties.Resources.preview_on;
break;
case 2:
btnNextMusic.BackgroundImage = global::musicforme.Properties.Resources.next_on;
break;
case 3:
SongAddPbtn.BackgroundImage = global::musicforme.Properties.Resources.list_on;
break;
}
}
private void btnNextMusic_Click(object sender, EventArgs e)
{
mod = 2;
MusicContorl.NextSong();
timer1.Interval = 200;
timer1.Start();
}
private void btnLastMusic_Click(object sender, EventArgs e)
{
mod = 1;
MusicContorl.LastSong();
timer1.Interval = 200;
timer1.Start();
}
private void btnLastMusic_MouseDown(object sender, MouseEventArgs e)
{
btnLastMusic.BackgroundImage = global::musicforme.Properties.Resources.preview_down;
}
private void btnNextMusic_MouseDown(object sender, MouseEventArgs e)
{
btnNextMusic.BackgroundImage = global::musicforme.Properties.Resources.next_down;
}
private void likeMusic_btn_Click(object sender, EventArgs e)
{
}
private void SongAddPbtn_MouseDown(object sender, MouseEventArgs e)
{
SongAddPbtn.BackgroundImage = global::musicforme.Properties.Resources.list_down;
}
private void SongAddPbtn_Click(object sender, EventArgs e)
{
mod = 3;
timer1.Interval = 200;
timer1.Start();
openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.RestoreDirectory = false;
openFileDialog1.Filter = "(*mp3)|*mp3|(*wav)|*.wav|All(*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = true;
DialogResult R = openFileDialog1.ShowDialog();
if (R == DialogResult.OK)
{
foreach (string SongFileName in openFileDialog1.FileNames)
{
MusicContorl.AddMusic(SongFileName, 1);
}
}
}
private void LoadMusicList()
{
string GetPath = Path.GetFullPath(".\\");
string FileList = GetPath "MusicList.txt";
if(File.Exists(FileList))
{
StreamReader streamReader = new StreamReader(FileList, System.Text.Encoding.Default);
string SongPath = "";
while(true)
{
if((SongPath=streamReader.ReadLine())==null)
break;
MusicContorl.AddMusic(SongPath,2);
}
streamReader.Close();
}
else
{
StreamWriter streamWriter = new StreamWriter(FileList);
streamWriter.Close();
}
}
private void label1_Click(object sender, EventArgs e)
{
MusicContorl.PageSub();
}
private void label2_Click(object sender, EventArgs e)
{
MusicContorl.PageAdd();
}
bool haha=false;
private void vlumePic_Click(object sender, EventArgs e)
{
if(!haha)
{
MusicContorl.VolumeDown();
haha = true;
}
else
{
MusicContorl.VolumeAdd();
haha = false;
}
}
int playmode = 1;
private void picPlayMode_Click(object sender, EventArgs e)
{
playmode ;
MusicContorl.PicPlayMode_Click();
if (playmode == 1)
{
picPlayMode.BackgroundImage = global::musicforme.Properties.Resources.playmode1;
}
else if (playmode == 2)
{
picPlayMode.BackgroundImage = global::musicforme.Properties.Resources.playmode2;
}
else
{
picPlayMode.BackgroundImage = global::musicforme.Properties.Resources.playmode3;
playmode = 0;
}
}
}
}
评论